FIND_PACKAGE(SWIG REQUIRED)
INCLUDE(${SWIG_USE_FILE})

FIND_PACKAGE(Octave REQUIRED)

SET(OCTAVE_WRAP_INCLUDE_DIRS 
	${CMAKE_CURRENT_SOURCE_DIR}
	${CMAKE_SOURCE_DIR}/src
	${CMAKE_SOURCE_DIR}/bindings
	${OCTAVE_INCLUDE_DIRS}
)
INCLUDE_DIRECTORIES(${OCTAVE_WRAP_INCLUDE_DIRS})

LINK_DIRECTORIES(${OCTAVE_LINK_DIRS})

set(SWIG_MODULE_biosignal_EXTRA_DEPS
${CMAKE_SOURCE_DIR}/bindings/biosignal_common.i)

MACRO(SET_OS_TARGET_PROPERTIES TARGET_NAME)
  IF(APPLE)                                                      
    SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES
      PREFIX "lib" SUFFIX ".jnilib")                                       
  ELSEIF(WIN32)                                                            
    SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES
      PREFIX "" SUFFIX ".dll")                                             
  ELSEIF(UNIX)
    SET_TARGET_PROPERTIES(${TARGET_NAME} PROPERTIES
      PREFIX "lib" SUFFIX ".so")
  ENDIF(APPLE)
ENDMACRO(SET_OS_TARGET_PROPERTIES)


SET_SOURCE_FILES_PROPERTIES(biosignal.i PROPERTIES CPLUSPLUS ON)
SWIG_ADD_MODULE(biosignalOctave octave biosignal.i )
SWIG_LINK_LIBRARIES(biosignalOctave ${OCTAVE_LIBRARY} biosignal ) 

SET_OS_TARGET_PROPERTIES(${SWIG_MODULE_biosignalOctave_REAL_NAME}) 

GET_TARGET_PROPERTY(LIB_NAME biosignalOctave LOCATION)
SET(NEW_LIB_NAME biosignal.oct)
 
ADD_CUSTOM_COMMAND(
  TARGET biosignalOctave
  POST_BUILD
  COMMAND ${CMAKE_COMMAND} -E copy ${LIB_NAME} ${NEW_LIB_NAME}
)

#INSTALL(TARGETS biosignalOctave DESTINATION lib/${BIOSIGNAL_LIB_API}/octave EXPORT biosignal-octave-targets)
INSTALL(FILES  ${CMAKE_CURRENT_BINARY_DIR}/biosignal.oct DESTINATION ${OCTAVE_LOCALVEROCTFILEDIR} )
#INSTALL(EXPORT biosignal-octave-targets DESTINATION lib/${BIOSIGNAL_LIB_API}/octave)  
